package com.xitang.common.dto;

import lombok.Builder;
import lombok.Data;

import java.util.Map;

@Builder
@Data
public class ResultVO<T> {
    private static int SUCCESS_DEFAULT_CODE = 0;

    private static int ERROR_DEFAULT_CODE = -1;

    private static String SUCCESS = "success";

    private static String ERROR = "出异常了，请与运维联系！";

    private int code;

    private String msg;

    private T data;

    private Map<String, Object> header;

    private long count;

    public static <T> ResultVO<T> success(T data) {
        return ResultVO.<T>builder()
                .code(SUCCESS_DEFAULT_CODE)
                .msg(SUCCESS)
                .data(data)
                .build();
    }

    public static <T> ResultVO<T> success(T data, Map<String, Object> headers) {
        return ResultVO.<T>builder()
                .code(SUCCESS_DEFAULT_CODE)
                .msg(SUCCESS)
                .data(data)
                .header(headers)
                .build();
    }

    public static <T> ResultVO<T> success(T data, long count) {
        return ResultVO.<T>builder()
                .code(SUCCESS_DEFAULT_CODE)
                .msg(SUCCESS)
                .data(data)
                .count(count)
                .build();
    }

    public static <T> ResultVO<T> error(T data) {
        return ResultVO.<T>builder()
                .code(ERROR_DEFAULT_CODE)
                .msg(ERROR)
                .data(data)
                .build();
    }
}
